<?php

class QOmslive
{
    /**
     *
     * @var Common_Db
     */
    private $_db;

    public function __construct()
    {
        $appUI = Zend_Registry::get('AppUI');
        $this->_db = new Common_Db('oms_live_' . $appUI->country);
        $this->_db->query ( "SET NAMES 'utf8'" );
		$this->_db->query ( "SET CHARACTER SET 'utf8'" );
    }

 	public function getOrderStatusDisplay()
    {
        $strQuery = 'SELECT * FROM `status_display`';
        $arrResult = $this->_db->fetchAll($strQuery);
        $this->_db->closeConnection();        
        return $arrResult;
    }
    
    public function getStatusOms($filters = null)
    {
    	$strQuery = 'SELECT status_display.*, oms_mapper.fk_id_sales_order_item_status
					FROM `status_display` AS status_display
					LEFT JOIN status_oms_mapper AS oms_mapper
					ON oms_mapper.fk_id_status_display = status_display.id_status_display';
    	
    	// WHERE
    	$strWhere = '';
    	if($filters)
    	{
    		foreach ($filters as $key => $value)
    			$strWhere .= " AND `$key`=$value";
    	}
    	$strQuery .= $strWhere;
    	
    	$arrResult = $this->_db->fetchAll($strQuery);
    	$this->_db->closeConnection();    	
    	return $arrResult;
    }
    
    public function insertDisplayStatus($arrParams)
    {
    	$this->_db->insert('status_display', $arrParams);
    	return $this->_db->lastInsertId('status_display', 'id_status_display');
    }
    
    public function insertOmsStatusMapper($arrParams)
    {
    	$this->_db->insert('status_oms_mapper', $arrParams);
    }
    
    public function deleteOmsStatusMapper($displayStatusId)
    {
    	$this->_db->delete('status_oms_mapper', "fk_id_status_display=$displayStatusId");
    }
    
    public function updateDisplayStatus($arrParams, $id_status_display)
    {
    	  $arrResult = $this->_db->update('status_display', $arrParams, "id_status_display=$id_status_display");
    }
    
    public function deleteDisplayStatus($displayStatusId)
    {
    	$this->_db->delete('status_display', "id_status_display=$displayStatusId");
    }    
    
    public function lastIdInsertDisplayStatus($primaryKey = null)
    {
    	
    }
}
?>